<!-- reportingResults -->
<template>
  <div class="page">
    <!-- 导航栏 -->
        <div class="navBar">
            <customNavBar :leftTetx=leftTetx :titleTest=titleTest></customNavBar>
        </div>
    <!-- <div style="text-align: left; padding-left: 13px; margin-top: 30px;" @click="goreportingJst()">
      <img class='contentg' src="../../assets/img/features/closeIcon.png" alt="">
    </div> -->

    <!-- <div class='cetjecsty'>
      <span v-if="route.query.isShow">报告查看二维码</span> 
      <span>报告生成结果</span>

    </div> -->
    <!-- 页面内容 -->
    <div class="content">
      <div style="margin-top: 61px;">
        <van-image width=48vw height=38vw :src="viewReport" />
      </div>
      <div>
        <!-- <van-progress class="progress" :percentage="80" :show-pivot=false stroke-width="12" />
                <div class='progressd'>
                    处理进度<span>(80%)</span>
                </div> -->
        <!-- <img  src="../../assets/img/features/pen.gif" alt=""> -->
      </div>
      <div class='progressc'>
        {{ reportGeneratingModel }}<span>{{ estimatedTime }}</span>{{ reportGeneratingModel0 }}
      </div>
      <div class="progressb" style="color: rgb(140, 140, 140);">
        {{ reportGeneratingModel1 }}
      </div>
    </div>
  </div>
  <div class='pageBj' v-if="showDialog">
    <div class="pageBjDiv">
      <div class='pageBjDivHeader'>温馨提示</div>
      <div class='pageBjDivsection'>您确认要退出本次服务吗?</div>
      <div class="pageBjDivBtoom">
        <div @click="onConfirm()">继续退出</div>
        <div @click="onCancel()">取消</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup name="reportingResultscz">
import { useRouter, useRoute } from "vue-router"
import { Toast } from '/@/utils/Message';
import { onMounted, onBeforeUnmount } from "vue"
import { reactive, ref } from 'vue'
import { JIAMIPublicData, JIMIPublicData } from '/@/utils/encrypt_sm2';
import { sm2 } from 'sm-crypto';
import { getReportResult, createCustomMark, true0rFalse, getReportEstimatedTime, getReportGeneratingModel } from "/@/api/auth/repot"
import customNavBar from "/src/components/NavBar/customNavBar.vue"
import viewReport from "../../assets/img/features/scz.gif"
import { getStorage } from "lib/tool";

const router = useRouter()
const route = useRoute()
const titleTest = ref("报告结果生成中")
const leftTetx = ref("")
const estimatedTime = ref("")
const reportGeneratingModel = ref("")
const reportGeneratingModel0 = ref("")
const reportGeneratingModel1 = ref("")
let face: any = ref('')   //如果金事同那边传来的face=true请求这个
const showDialog = ref<boolean>(false)

const onConfirm = () => {
  // window.location.replace('./reportingResultwxts')
  router.push({ path: 'reportingResultwxts' })
}
const onCancel = () => {
  // 取消操作
  showDialog.value = false;
}
const goreportingJst = (): void => {
  showDialog.value = true
}

const backHome = () => {
  // 获取 User Agent
  var userAgent = navigator.userAgent.toLowerCase();
  // 判断是否在微信中打开
  if (userAgent.indexOf('micromessenger') !== -1) {
    setTimeout(function () {
      //这个可以关闭安卓系统的手机
      document.addEventListener(
        "WeixinJSBridgeReady",
        function () {
          WeixinJSBridge.call("closeWindow");
        },
        false
      );
      //这个可以关闭ios系统的手机
      WeixinJSBridge.call("closeWindow");
    }, 500);
  } else {
    console.log('当前页面不在微信中打开');
    if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
      window.location.href = "about:blank";
    } else if (userAgent.indexOf('Android') > -1 || userAgent.indexOf('Linux') > -1) {
      window.opener = null; window.open('about:blank', '_self', '').close();
    } else {
      window.opener = null;
      window.open("about:blank", "_self");
      window.close();
    }
  }
}

// 如果金事同那边传来的face=true请求这个

const getCreateCustomMark = async () => {
  if (face) {
    // 从金世同过生成用户唯一标识，加到请求头  现在无法实现
    await createCustomMark({ taskCode: sessionStorage.getItem('taskCode') || route.query.taskCode, policyKey: route.query.policyKey, createFlag: 0 }).then((res: any) => {
      // await createCustomMark({taskCode: route.query.taskCode}).then((res: any) => {
      if (res.code == 200) {
        sessionStorage.setItem('customToken', res.customToken)
      } else {
        Toast('系统错误，请联系管理员')
      }
    })
  }

}

const getob = async () => {
  await getReportResult({ taskCode: sessionStorage.getItem('taskCode') || route.query.taskCode }).then((res: any) => {
    // await getReportResult({taskCode:route.query.taskCode  }).then((res: any) => {
    if (res.code == 200) {
      switch (res.status) {
        case '5': ''; // 生成中
          break;
        case '10':  // 无有效保单
          router.push({ path: '/reportingResultswyx', query: { taskCode: res.taskCode, reportCode: res.reportCode } })
          break;
        case '6':  // 已生成
          // router.push({
          //   path: '/reportingResultsysc', query: {
          //     taskCode:res.taskCode,
          //   }
          // })
          router.push({
            path: '/reportingResultxysc', query: {
              taskCode: res.taskCode,
            }
          })
          break;
        case '11': // 无可检视
          router.push({ path: '/reportingResultswkjs', query: { taskCode: res.taskCode, reportCode: res.reportCode } })
          break;
        case '12': // 生成失败
          router.push({ path: '/reportingResultcsb', query: { taskCode: res.taskCode, reportCode: res.reportCode, errCode: res.errCode } })
          break;
        case '14': // 报告结果不一致
          router.push({ path: '/reportingResultsbyz', query: { taskCode: res.taskCode, reportCode: res.reportCode, errCode: res.errCode } })
          break;
        case '15': // 部分成功
          router.push({
            path: '/reportingResultxysc', query: {
              taskCode: res.taskCode,
            }
          })
          break;
        case '16':
          router.push({ path: '/reportingResultcsb', query: { taskCode: res.taskCode, reportCode: res.reportCode, errCode: res.errCode } })
          break;
        case '17': // 报告超时
          router.push({ path: '/reportingResultlecs', query: { taskCode: res.taskCode, reportCode: res.reportCode } })
          break;
      }
    }
  })
}
let time: any = ''
onMounted(async () => {
  face.value = route.query.face
  if (route.query.face) {
    getCreateCustomMark()
  }
  if (route.query.repo) {
    face.value = 'true'
  }
  // getReportEstimatedTime().then((res: any) => {
  //     if(res.code == 200) estimatedTime.value = res.data.estimatedTime
  // })
  getReportGeneratingModel({ taskCode: sessionStorage.getItem('taskCode') || route.query.taskCode }).then((res: any) => {
    if (res.code == 200) {
      // estimatedTime.value = res.data.reportGeneratingModel.split('$')[1]
      // estimatedTime.value = sessionStorage.getItem('estimateSeconds') || res.data.reportGeneratingModel.split('$')[1]
      estimatedTime.value = sessionStorage.getItem('estimateSeconds') || res.data.estimateSeconds
      reportGeneratingModel.value = res.data.reportGeneratingModel.split('$')[0]
      reportGeneratingModel0.value = res.data.reportGeneratingModel.split('$')[2]
      // console.log(reportGeneratingModel.value)
      // console.log(estimatedTime.value)
      // console.log(reportGeneratingModel0.value)
      // reportGeneratingModel1.value = res.data.reportGeneratingModel .split('$')[3]
    } else if (res.code == 402 ) {
      router.push({ path: 'reportingResultwxts' })
    }
  })
  await setTimeout(() => {
    getob()
  }, 3000)
  time = setInterval(() => {
    getob()
  }, 10000)
})
//清除
onBeforeUnmount(() => {
  clearInterval(time)
  time = null
})
</script>

<!-- less嵌套设置 -->
<style lang="less" scoped>
.pageBj {
  top: 0;
  width: 100%;
  height: 100%;
  display: flex;
  position: absolute;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);

  .pageBjDiv {
    width: 300px;
    // padding: 10px 20px;
    border-radius: 10px;
    background: #ffffff;

    .pageBjDivHeader {
      margin-top: 17px;
      font-size: 14px;
      font-weight: bold;
    }

    .pageBjDivsection {
      margin-top: 17px;
      font-size: 13px;
    }

    .pageBjDivBtoom {
      display: flex;
      width: 100%;
      margin-top: 17px;
      justify-content: center;
      border-top: 1px solid #f3f3f3;

      div {
        padding: 10px 0;
        width: 50%;
      }

      div:last-child {
        color: #ffffff;
        background: #2c56ce;
        border-bottom-right-radius: 7px;
      }
    }
  }
}

.contentg {
  width: 30px;
  height: 27px;
}

.page {
  background-color: #FFFFFF;
  height: 100vh;
  width: 100vw;
  overflow-x: hidden;

  .content {
    width: 100%;
    padding-top: 68px;
    overflow: hidden;
    margin-top: 52px;
    padding-bottom: 60px;
    // background-color: #f7f8fa;

    .progress {
      margin-top: 36px;
      margin-left: 20%;
      margin-right: 20%;
    }

    .progressd {
      color: #222222;
      font-size: 14px;
      font-weight: 500;
      margin-top: 22px;

      span {
        color: #007DFA;
      }
    }

    .progressc {
      width: 75%;
      max-width: 550px;
      margin: 0 auto;
      font-size: 16px;
      color: #222222;
      font-weight: 200;
      margin-top: 22px;
      text-align: left;
      // letter-spacing: 1.7px;

      span {
        color: rgba(0, 125, 250, 1);
        font-weight: bold;
      }
    }

    .progressb {
      width: 100%;
      max-width: 550px;
      margin: 0 auto;
      font-size: 14px;
      color: #222222;
      font-weight: 200;
      margin-top: 22px;
      text-align: left;
      letter-spacing: 1.7px;
    }
  }
}
</style>
